$(function () {
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURIComponent(r[2]); return null;
    }
    // console.log(getQueryString("classId"),getQueryString("className"))

    // $('#classId').val(localStorage.getItem("classId"))
    // $('#className').val(localStorage.getItem("className"))
    $('#classId').val(getQueryString("classId"))
    $('#className').val(getQueryString("className"))
    $("#btnAdd").click(function () {
        // console.log(localStorage.getItem("className"),11221)
        let classId = $('#classId').val()
        let className = $("#className").val()
        if(className==null || classId.trim().length==0){
            $('#className').parent().addClass("has-error")
            $('#className').focus()
        } else {
            $.ajax({
                url:"/classes?classId="+classId+"&className="+className,
                type:"POST",
                success: function (data) {
                    console.log(data)
                    location.href="index.html";
                },
                error: function (data) {
                    console.log(data)
                }
            })
        }

    })
})